<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
	<link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
	<link rel="stylesheet" href="/css/treetable/jquery.treetable.css"/>
	<link rel="stylesheet" href="/css/treetable/jquery.treetable.theme.default.css"/>
	<link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
	<link rel="stylesheet" type="text/css" href="/at-js/css/jquery.atwho.css">
	<script src="/js/libs/jquery-2.1.1.min.js"></script>
	<script src="/js/bootstrap/bootstrap.min.js"></script>
	<script src="/js/bootstrap/bootstrap-select.min.js"></script>
	<script src="/js/jq.js"></script>
	<script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script src="/js/common.js"></script>
	<script src="/layui/layui.js"></script>
	<script src="/js/dict.js"></script>
	<script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
	<script src="/js/my/ztree-menu.js"></script>
	<script src="/js/my/permission.js"></script>
	<script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
	<script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
	<script src="/js/libs/jquery.treetable.js"></script>
	<script src="/js/plugin/jquery-caret/jquery.caret.js"></script>
	<script src="/at-js/js/jquery.atwho.js"></script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-md-offset-2 col-lg-offset-2">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<input type="hidden" id="projectId" name="projectId">
			<div class='form-group'>
				<label class='col-md-4 control-label'>任务名称</label>
				<div class='col-md-8'>
					<input class='form-control' placeholder='任务名称' type='text' name='name' id='name'
						   data-bv-notempty='true' data-bv-notempty-message='任务名称 不能为空'>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-4 control-label'>执行者：</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='participantId' id='participantId'
						   data-bv-notempty='true' data-bv-notempty-message='执行者 不能为空'>
					<input style="width: 90%;float: left;" class='form-control' placeholder='执行者' type='text'
						   name='participantName' id='participantName' data-bv-notempty='true'
						   data-bv-notempty-message='执行者 不能为空'
						   readonly>

				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>预计工时：</label>
				<div class='col-md-8'>
					<input class="form-control" placeholder="预计工时" name="estimateWorkingHours" id="estimateWorkingHours"
						   data-bv-notempty='true' data-bv-notempty-message='预计工时 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>任务描述：</label>
				<div class='col-md-8'>
					<div class="panel panel-default" name="description" id="description" contenteditable="true"
						 style="width: 100%; min-height: 100px;"></div>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>截止日期</label>
				<div class='col-md-8'>
					<input class='form-control' placeholder='截止日期' type='text' name='deadline' id='deadline'
						   data-bv-notempty='true' data-bv-notempty-message='截止日期 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>优先级:</label>
				<div class='col-md-8'>
					<select class="form-control input-sm selectpicker show-tick" name="grade" id="grade"
							title="任务状态" data-live-search="true"></select>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>附件</label>
				<div class="layui-upload col-md-8">
					<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="selectScreenshotPath">
						选择多文件
					</button>
					<input type="hidden" value="" id="screenshotPath" name="screenshotPath">
					<button type="button" class="layui-btn layui-btn-sm" id="uploadScreenshotPath">开始上传</button>
					<div class="layui-upload-list">
						<table class="layui-table" style="table-layout:fixed;">
							<thead>
							<tr>
								<th>文件名</th>
								<th>大小</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="screenshotPathList"></tbody>
						</table>
					</div>
				</div>
			</div>
		</fieldset>
	</form>
</div>

	<script type="text/javascript">
	    $(function () {
            $('#form').bootstrapValidator();
        });

        var pers = checkPermission();

        var status = showDictSelect('status', 'task_status', '', '0');
        var grade = showDictSelect('grade', 'dept_level', '', '1');

		initData();
        function initData() {
            var id = getUrlParam("id");
            if (id) {
                $.ajax({
                    type: 'get',
                    url: '/task/' + id,
                    async: false,
                    success: function (json) {
                        if (json.code === 0) {
                            var data = json.data;
                            $('#name').val(data.name);
                            $('#projectId').val(data.projectId);
                            $('#participantId').val(data.participantId);
                            $('#participantName').val(data.participantName);
                            $('#estimateWorkingHours').val(data.estimateWorkingHours);
                            $('#description').html(data.description);
                            $('#deadline').val(data.deadline);
                            $('#grade').val(data.grade);
                            $('#screenshotPath').val(data.screenshotPath);
                            var screenshotPaths = data.screenshotPaths;
                            $('#screenshotPathList').empty();
                            if (screenshotPaths) {
                                $.each(screenshotPaths, function (index, file) {
                                    var tr = $(['<tr id="upload-' + index + '">'
                                        , '<td style ="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'
                                        , '<a target="_blank" data-id="' + file.id + '" class="screenshotPathFile" href="/files' + file.url + '">' + file.fileName + '</a>'
                                        , '</td>'
                                        , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                                        , '<td>已上传</td>'
                                        , '<td>'
                                        , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                                        , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                                        , '</td>'
                                        , '</tr>'].join(''));

                                    //单个重传
                                    tr.find('.demo-reload').on('click', function () {
                                        obj.upload(index, file);
                                    });

                                    //删除
                                    tr.find('.demo-delete').on('click', function () {
                                        // delete files[index]; //删除对应的文件
                                        tr.remove();
                                        // 重新获得所有上传文件
                                        $('#screenshotPath').val('');
                                        $('.screenshotPathFile').each(function () {
                                            $('#screenshotPath').val($('#screenshotPath').val() + '|' + $(this).data('id'));
                                        });
                                    });

                                    $('#screenshotPathList').append(tr);
                                });
                            }
                        }
                    }
                });
            }
        }
	</script>
</body>
</html>
